import time
from Common.Base import Base, open_browser

register_url = "http://localhost:8080/ecshop/user.php?act=register"


# 表现层：页面可见的元素，制作定位器
class RegisterPage(Base):
    username_loc = ("name", "username")  # 用户名的定位器
    email_loc = ('name', 'email')  # 邮箱的定位器
    password_loc = ("name", "password") # 密码的定位器
    confirm_password_loc = ('name', 'confirm_password')  # 确认密码的定位器
    phone_loc = ('name', "extend_field5")  # 手机号码定位器
    Submit_loc = ("name", "Submit")   # 注册的定位器


    def input_username(self, username):
        """
        输入用户名
        :return:
        """
        self.send_keys(self.username_loc, username)

    def input_email(self, email):
        """
        输入邮箱
        :return:
        """
        self.send_keys(self.email_loc, email)

    def input_password(self, password):
        """
        输入密码
        :return:
        """
        self.send_keys(self.password_loc, password)

    def input_confirm_password(self, confirm_password):
        """
        确认输入密码
        :return:
        """
        self.send_keys(self.confirm_password_loc, confirm_password)

    def input_phone(self, extend_field5):
        """
        输入手机号码
        :return:
        """
        self.send_keys(self.phone_loc, extend_field5)

    def click_register(self):
        """
        点击注册按钮
        :return:
        """
        self.click(self.Submit_loc)


if __name__ == '__main__':
    reg = RegisterPage(open_browser())
    reg.open_url(register_url)
    reg.input_username('sijingjing')
    reg.input_email('1148972564@qq.com')
    reg.input_password('s123258.')
    reg.input_confirm_password('s123258.')
    reg.input_phone('17815097775')
    reg.click_register()
    time.sleep(5)
    reg.close_browser()
